/**
 * 
 */
package org.cnbi.utils.chart.json;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.cnbi.utils.chart.base.BaseChart;
import org.cnbi.utils.chart.component.Column;
import org.cnbi.utils.chart.json.component.JsonData;
import org.cnbi.utils.chart.json.component.JsonStyles;
import org.cnbi.utils.chart.Constants;
import org.cnbi.utils.pojo.DynamicBean;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;


/**
 * @company 中国经邦
 * @author Administrator
 * @date: 2014年3月14日下午5:25:46
 * @version: V1.0 单系列图表
 */
public class JsonSingleSeries implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<JsonData> data;

	private BaseChart chart;
	@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
	private JsonStyles styles;
	
	@JsonIgnore
	private boolean toolTextFlag = false;

	public JsonSingleSeries() {

	}
	
	public JsonSingleSeries(BaseChart chart) {
     this.chart = chart;
	}


	/**
	 * @param data
	 * @param chart
	 * @param styles
	 */
	public JsonSingleSeries(List<JsonData> data, BaseChart chart, JsonStyles styles) {
		super();
		this.data = data;
		this.chart = chart;
		this.styles = styles;
	}

	/**
	 * @param data
	 * @param chart
	 * @param styles
	 */
	public JsonSingleSeries(List<JsonData> data, BaseChart chart) {
		this.data = data;
		this.chart = chart;
	}

	private void setMainData(List<Column> colList, List<DynamicBean> datas) {
		data = new ArrayList<JsonData>();
		String pro = Constants.INDEX+"0", color = Constants.COLOR;
		for (int j = 0, lj = datas.size(); j < lj; j++) {
			DynamicBean values = datas.get(j);
			JsonData dataBean = new JsonData();
			if(!values.getValue(pro).toString().equals(Constants.TOTALSTRING)){
				for (int i = 0, len = colList.size(); i < len; i++) {
					Column col = colList.get(i);
					String index = col.getIndex();
					Object temp = values.getValue(index);
					 String tempValue = Constants.ZEROVALUE;
					  if(null != temp){
						  tempValue = temp.toString();
					  }
					if (index.equals(pro)) {// 必须要有index0属性
						dataBean.setLabel(tempValue);
					} else if (index.equals(color)) {
						dataBean.setColor(tempValue);
					} else {
						dataBean.setValue(tempValue);
					}
				}
				
				data.add(dataBean);
			}
			

		}

	}

	/**
	 * @param data
	 * @param chart
	 * @param styles
	 */
	public JsonSingleSeries(List<Column> colList, List<DynamicBean> datas, BaseChart chart) {
		this.chart = chart;
		setMainData(colList, datas);
	}

	public List<JsonData> getData() {
		return data;
	}

	public void setData(List<JsonData> data) {
		this.data = data;
	}
	
	public void setDataList(List<DynamicBean> datas,List<Column> colList) {
		setMainData(colList, datas);
	}

	public BaseChart getChart() {
		return chart;
	}

	public void setChart(BaseChart chart) {
		this.chart = chart;
	}

	public JsonStyles getStyles() {
		return styles;
	}

	public void setStyles(JsonStyles styles) {
		this.styles = styles;
	}

}
